/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* Author: GoldenKevin
	NPC Name: 		Mar the Fairy
	Map(s): 		Hidden Street : Marr's Forest (101000200)
	Description: 		Revives expired pets with Water of Life
*/
importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.client.MapleCharacter);

var status = 0;
var amount;
var pet = null;
var pet2;

function start() {
	status = -1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			cm.sendSimple("Hey there, I'm the all-in-one pet NPC. What would you like to do? #b\r\n#L0#Evolve my Baby Dragon or Baby Robo.#l\r\n#L1#Revive my expired pet.#l\r\n#L2#Buy Pet Food.#l#k");
		} else if (status == 1) {
			if (selection == 0) {
				var itemId = cm.getPlayer().getPet(0) != null ? cm.getPlayer().getPet(0).getItemId() : 0;
				if (cm.haveItem(5000028)) {
					if (!cm.haveItem(5000029)) {
						cm.gainItem(5000028, -1);
						cm.gainItem(5000029, 1);
						cm.sendOk("I don't know how you got that egg, but it has hatched, apparently!");
					} else {
						cm.sendOk("How did you get that egg? It's not hatching because you already have a baby dragon.");
					}
					cm.dispose();
				} else if (cm.haveItem(5000047)) {
					if (!cm.haveItem(5000048)) {
						cm.gainItem(5000047, -1);
						cm.gainItem(5000048, 1);
						cm.sendOk("I don't know how you got that egg, but it has hatched, apparently!");
					} else {
						cm.sendOk("How did you get that egg? It's not hatching because you already have a baby robo.");
					}
					cm.dispose();
				} else if (cm.getPlayer().getPet(0) == null) {
					cm.sendOk("Please equip your pet first.");
					cm.dispose();
				} else if (!cm.haveItem(5380000,1) || (itemId < 5000029 || itemId > 5000033) && (itemId < 5000048 || itemId > 5000053)) {
					cm.sendOk("You do not meet the requirements. You need #i5380000##t5380000#, as well as either one of #d#i5000029##t5000029##k, #g#i5000030##t5000030##k, #r#i5000031##t5000031##k, #b#i5000032##t5000032##k, or #e#i5000033##t5000033##n equipped for dragons, or #d#i5000048##t5000048##k, #b#i5000049##t5000049##k, #r#i5000050##t5000050##k, #g#i5000051##t5000051##k, #d#i5000052##t5000052##k, or #k#i5000053##t5000053##k for robos. Please come back when you do.");
					cm.dispose();
				} else if (cm.getPlayer().getPet(0).getLevel() < 15) {
					cm.sendOk("Your pet you wish to evolve must be your lead pet, and it must be level 15 or above to evolve.");
					cm.dispose();
				} else if (itemId == 5000029) {
					pet = 5000029;
					cm.sendYesNo("I see you have a Baby Dragon as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000030) {
					pet = 5000030;
					cm.sendYesNo("I see you have a Green Dragon as your lead pet. Would you like to try your chance at re-evolving "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000031) {
					pet = 5000031;
					cm.sendYesNo("I see you have a Red Dragon as your lead pet. Would you like to try your chance at re-evolving "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000032) {
					pet = 5000032;
					cm.sendYesNo("I see you have a Blue Dragon as your lead pet. Would you like to try your chance at re-evolving "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000033) {
					pet = 5000033;
					cm.sendYesNo("I see you have a Black Dragon as your lead pet. Would you like to try your chance at re-evolving "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000048) {
					pet = 5000048;
					cm.sendYesNo("I see you have a Baby Robo as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000049) {
					pet = 5000049;
					cm.sendYesNo("I see you have a Blue Robo as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000050) {
					pet = 5000050;
					cm.sendYesNo("I see you have a Red Robo as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000051) {
					pet = 5000051;
					cm.sendYesNo("I see you have a Green Robo as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000052) {
					pet = 5000052;
					cm.sendYesNo("I see you have a Gold Robo as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else if (itemId == 5000053) {
					pet = 5000053;
					cm.sendYesNo("I see you have a Gorilla Robo as your lead pet. Would you like to evolve "+cm.getPlayer().getPet(0).getName()+"?");
				} else {
					cm.sendOk("You don't have a Dragon or Robo equipped as your lead pet.");
					cm.dispose();
				}
			} else if (selection == 1) {
				status = 10;
				pet = cm.getPlayer().checkExpiredPet();
				if (pet != null) {
					cm.sendNext("I see you have an expired pet.");
				} else {
					cm.sendOk("You do not have any expired pets.");
					cm.dispose();
				}
			} else if (selection == 2) {
				status = 20;
				cm.sendGetNumber("Each pet food carton costs 500 mesos and satisfies your pet around 25 fullness. How many would you like to buy?", 1, 1, 100)
			}
		} else if (status == 2) {
			var after = cm.evolve(pet);
			cm.gainItem(5380000, -1);
			if (pet > 5000028 && pet < 5000034) {
				amount = "#bSWEET! IT WORKED!#k Your dragon has grown beautifully! #rYou may find your new pet under your 'CASH' inventory.\r It used to be a #i" + pet + "##t" + pet + "#, and now it's \r a #i" + after + "##t" + after + "#!#k \r\n\r\n#fUI/UIWindow.img/QuestIcon/4/0#\r\n#v"+after+"# #t"+after+"#\r\n\r\n#fUI/UIWindow.img/QuestIcon/8/0# 1000 EXP\r\n#fUI/UIWindow.img/QuestIcon/9/0# 2 Closeness\r\n#fUI/UIWindow.img/QuestIcon/6/0# 1 Fame\r\n#fUI/UIWindow.img/QuestIcon/7/0# 100 Mesos";
			} else if (pet > 5000047 && pet < 5000054) {
				amount = "#bSWEET! IT WORKED!#k Your robo has grown beautifully! #rYou may find your new pet under your 'CASH' inventory.\r It used to be a #i" + pet + "##t" + pet + "#, and now it's \r a #i" + after + "##t" + after + "#!#k \r\n\r\n#fUI/UIWindow.img/QuestIcon/4/0#\r\n#v"+after+"# #t"+after+"#\r\n\r\n#fUI/UIWindow.img/QuestIcon/8/0# 1000 EXP\r\n#fUI/UIWindow.img/QuestIcon/9/0# 2 Closeness\r\n#fUI/UIWindow.img/QuestIcon/6/0# 1 Fame\r\n#fUI/UIWindow.img/QuestIcon/7/0# 100 Mesos";
			}
			cm.sendOk(amount);
			cm.dispose();
		} else if (status == 11) {
			if (cm.haveItem(5180000)) {
				cm.sendYesNo("Would you like to revive it with the Water of Life?");
			} else {
				cm.sendOk("You do not have a Water of Life. You cannot revive your pet without it.");
				cm.dispose();
			}
		} else if (status == 12) {
			cm.getPlayer().revivePet(pet);
			cm.gainItem(5180000, -1);
			cm.sendOk("Your pet has been revived and it's life has been extended by another 90 days!");
			cm.dispose();
		} else if (status == 21) {
			amount = selection;
			cm.sendYesNo("Do you want to buy "+selection+" cartons of Pet Food for "+(selection * 500)+" mesos?");
		} else if (status == 22) {
			cm.gainItem(2120000, amount);
			cm.gainMeso(-(amount * 500));
			cm.sendOk("There you go! "+amount+" cartons of Pet Food for your hungry pet.");
			cm.dispose();
		} else {
			cm.dispose();
		}
	}
}